﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SpaceNeedle.x6473.WindowsPhone.Common
{
    public class LoremIpsum
    {
        public const string Text = @"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

        public string Get(int count)
        {
            return Get(count, Environment.NewLine);
        }

        public string Get(int count, string separator)
        {
            return String.Join(separator, Enumerable.Repeat(LoremIpsum.Text, count));
        }

        public static string GetRandom(int minWords, int maxWords, int minSentences, int maxSentences, int numParagraphs)
        {
            return GetRandom(minWords, maxWords, minSentences, maxSentences, numParagraphs, Environment.NewLine);
        }

        public static string GetRandom(int minWords, int maxWords, int minSentences, int maxSentences, int numParagraphs, string separator)
        {
            var words = new[]{"lorem", "ipsum", "dolor", "sit", "amet", "consectetuer",
        "adipiscing", "elit", "sed", "diam", "nonummy", "nibh", "euismod",
        "tincidunt", "ut", "laoreet", "dolore", "magna", "aliquam", "erat"};

            var rand = new Random();
            int numSentences = rand.Next(maxSentences - minSentences)
                + minSentences + 1;
            int numWords = rand.Next(maxWords - minWords) + minWords + 1;

            string result = string.Empty;

            for (int p = 0; p < numParagraphs; p++)
            {
                if (p > 0)
                {
                    result += separator;
                }

                for (int s = 0; s < numSentences; s++)
                {
                    for (int w = 0; w < numWords; w++)
                    {
                        if (w > 0) { result += " "; }
                        result += words[rand.Next(words.Length)];
                    }
                    result += ". ";
                }
            }

            return result;
        }
    }
}
